<template>
  <el-card class="box-card">
    <div slot="header" class="clearfix">
      <span>平台余额</span>
    </div>
    <el-table :data="pageList" class="el-table-align-center" v-loading="loading" border>
      <el-table-column label="主账户余额" prop="balance">
        <template slot-scope="{row}">{{row.balance | currency}}</template>
      </el-table-column>
      <el-table-column label="提现冻结金额" prop="channelId">
        <template slot-scope="{row}">{{row._balance | currency}}</template>
      </el-table-column>
      <el-table-column label="授信额度" prop="validBalance">
        <template>{{userInfo.amount | currency}}</template>
      </el-table-column>
      <el-table-column label="会员代充(授信代充/总代充)" prop="validBalance">
        <template>{{userInfo.payOutAmount | currency}}</template>
      </el-table-column>
      <el-table-column label="代理授信" prop="validBalance">
        <template>{{userInfo.proxyCreditedAmount | currency}}</template>
      </el-table-column>
      <el-table-column label="授信账户余额" prop="validBalance">
        <template>{{'(后台提供字段)'}}</template>
      </el-table-column>
      <el-table-column label="代充账户余额" prop="validBalance">
        <template>{{userInfo.validAllocateAmount | currency}}</template>
      </el-table-column>
    </el-table>
  </el-card>
</template>

<script>
import { getMemberBalance } from '@/services/api/member';
import { applyCreditClearReorder } from '@/services/api/recharge';
import { grid, factory } from '@/build';

export default {
  name: 'platform-balance',
  mixins: [grid, factory],
  props: {
    member: {
      type: Object,
    },
  },
  data() {
    return {
      pageList: [{
        amount: 0,
        payOutAmount: 0,
        validAllocateAmount: 0,
      }],
      balanceList: [],
      userInfo: {},
      dialogVisible: false,
      form: {
        userId: this.$store.state.member.member_id,
      },
      refRule: {
        money: factory.getRule('money'),
      },
    };
  },
  mounted() {
    this.bindGet(getMemberBalance, 'balanceList', {
      action: 'getGrid',
      sendingData: 'form',
      format: (data) => {
        const balance = _.find(data, { channelId: 0 });
        const _balance = _.find(data, { channelId: 101 });
        this.$set(this.pageList[0], 'balance', balance.balance);
        this.$set(this.pageList[0], '_balance', _balance.balance);
      },
    });
    this.bindGet(applyCreditClearReorder, 'userInfo', {
      sendingData: { proxyId: this.member.id },
    });
    this.getAll();
  },
};
</script>

<style lang="scss">
.el-table-no-head {
  .el-table__header-wrapper {
    display: none;
  }
}
</style>
